import os
from xml.dom.minidom import parse

res_dir = 'res/origin/'
default_string_path = 'res/origin/values/strings.xml'


def is_lan_dir(str):
    return '-' in str


def get_lan_file_keys(file):
    keys = []
    dom = parse(file)
    for node in dom.getElementsByTagName('string'):
        translatable = node.getAttribute('translatable')
        ignore = False
        # 1. 忽略 translatable 为false
        if translatable == 'false':
            ignore = True
        # 2. 忽略 值中为@string/开头
        for item in node.childNodes:
            value = item.nodeValue
            if value.startswith('@string/'):
                ignore = True
        if ignore:
            continue
        name = node.getAttribute('name')
        keys.append(name)
    return keys


def main():
    default_keys = get_lan_file_keys(default_string_path)

    lan_dirs = list(filter(is_lan_dir, os.listdir(res_dir)))
    for lan_dir in lan_dirs:
        lan_file = res_dir + lan_dir + '/strings.xml'
        lan_keys = get_lan_file_keys(lan_file)
        untranslated_keys = filter(lambda key: key not in lan_keys, default_keys)
        print('{0:13s}'.format(lan_dir), list(untranslated_keys))


if __name__ == '__main__':
    main()
